package com.learn.job;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author : Yu.Tan
 * @date : 2023/3/23 10:43
 * @desc : **
 */
public class QuartJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("要去数据库扫描啦。。。");
    }

    public static void main(String[] args) throws SchedulerException {
        //创建任务
        JobDetail jobDetail = JobBuilder.newJob(QuartJob.class)
                .withIdentity("job1", "group1")
                .build();
        //创建触发器
        SimpleTrigger trigger = TriggerBuilder
                .newTrigger()
                .withIdentity("trigger1", "group2")
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule()
                        .withIntervalInSeconds(3)
                        .repeatForever())
                .build();
        //创建调度器
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        //将任务、触发器放入调度器
        scheduler.scheduleJob(jobDetail,trigger);
        //开始调度
        scheduler.start();
    }
}
